Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Independent Table Elements #34

Merged
merged 23 commits into from
Jul 24, 2023
Merged

Independent Table Elements #34

merged 23 commits into from
Jul 24, 2023

Conversation

aaroncox
Copy link
Member

This PR breaks the dependencies between Contract, Table, and TableCursor - which allows developers the opportunity to use each element individually if they choose to do so.

*
* @returns A new cursor with updated parameters.
*/
query(query: Query) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I guess one side effect of decoupling table and table cursor is that this now feels out of place 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah if we want it back - it's going to need to be a function that translates a TableCursor back into a Table call, and that kinda re-adds that dependency this was seeking to remove.

I'm thinking maybe we add this feature into whatever a future QueryBuilder might be, and leave it off for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!


if (this.next_key) {
lower_bound = this.next_key
}

let indexPosition = this.tableParams.index_position || 'primary'

if (this.indexPositionField) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to admit that I do love the fact that this is no longer needed 😁


const rows =
Copy link
Contributor

@dafuga dafuga Jul 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable assignment does a lot and is a bit difficult to follow so I would probably break it up into different steps.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave this a shot, and added some comments.

// Determine if we need to decode the rows, based on if:
// - json parameter is false, meaning hex data will be returned
// - type parameter is not set, meaning the APIClient will not automatically decode
const requiresDecoding =
this.params.json === false && !(query as API.v1.GetTableRowsParamsTyped).type
// Retrieve the rows from the result, decoding if needed
const rows: RowType[] = requiresDecoding
? result.rows.map((data) =>
Serializer.decode({
data,
abi: this.abi,
type: this.type,
})
)
: result.rows

I'm not sure how much more I think we should split it out, unless we wanted to get rid of the ternary operator, and instead do...

let rows = thing 
if (decode) { 
  rows = otherThing 
}

private rowsCount = 0
private maxRows: number = Number.MAX_SAFE_INTEGER

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that these were far from perfect, but we will still want to have some JSDoc statements here, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah absolutely. I just kept seeing so many things changing - that I wanted to redo them all if this was the direction we wanted to go 👍


const mockClient = makeClient('https://eos.greymass.com')

suite('Cursor', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

)
})
// TODO: Discuss and remove? No longer works since query is a Table method
// test('should allow you to chain index query statements', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess we can just remove this. I personally kind of liked the fact that you could chain query statements like this, but given that the cursor and table classes are now built to be used independently, it no longer really makes sense to have a query method on the cursor.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed for now, and left a link to this discussion in the commit.

@@ -0,0 +1,382 @@
// generated by @greymass/abi2core
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to commit this? 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the unit tests are using it to test with Struct instances from abi2core.

@@ -0,0 +1,799 @@
// generated by @greymass/abi2core
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this?

Copy link
Contributor

@dafuga dafuga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more I think about it, the more I realize that this is probably a good change to make! I left you some comments about some minor stuff, but overall the PR looks good! Thanks for working on this!

Same logic as before, just different syntax.
Resulting logic is the same, just simplified the Math.min() call
@aaroncox aaroncox changed the base branch from dev to rowtype-generics-maybe-fix July 24, 2023 22:47
@aaroncox aaroncox changed the base branch from rowtype-generics-maybe-fix to dev July 24, 2023 22:47
@aaroncox aaroncox merged commit aa3c1f5 into dev Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants